home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 8.3 KB | 241 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFileAc.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #include <Limits.h>
-
- #ifndef FWFILEAC_H
- #include "FWFileAc.h"
- #endif
-
- #ifndef FWFILREP_H
- #include "FWFilRep.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCDEF_H
- #include "FWExcDef.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FILES__)
- #include "Files.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(IO_H)
- #include "io.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment File
- #endif
-
- #ifdef FW_BUILD_WIN16
- extern "C" void FAR PASCAL DOS3Call(); // We use this instead of calling "Int 21h"
- #endif
-
- //========================================================================================
- // CLASS FW_CFileSink
- //
- // This is a reference counted class. It maintains a FW_TCountedPtr which points to a
- // FW_CFileRep. All copies of this class will reference the same rep and
- // therefore will share the same access permissions and file mark position.
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::FW_CFileSink
- //
- // Copy constructor. Does not copy the fRep itself, but only copies the pointer.
- //----------------------------------------------------------------------------------------
- FW_CFileSink::FW_CFileSink(const FW_CFileSink& other) :
- FW_CRandomAccessSink(),
- fRep(other.fRep)
- {
- FW_END_CONSTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::FW_CFileSink
- //
- // Internal method. Clients should generally not use this constructor.
- // Attaches the file access to the given access rep. This routine is used mainly by
- // exceptions to reference this FW_CFileSink during error handling.
- //----------------------------------------------------------------------------------------
- FW_CFileSink::FW_CFileSink(FW_PFile rep) :
- FW_CRandomAccessSink(),
- fRep(rep)
- {
- FW_END_CONSTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::~FW_CFileSink
- //----------------------------------------------------------------------------------------
- FW_CFileSink::~FW_CFileSink()
- {
- FW_START_DESTRUCTOR
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::Read
- //
- // Reads count bytes from the file into the buffer specified by destination. The bytes
- // will be read starting at the current file position. The user is responsible for
- // providing the buffer.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::Read(void* destination,
- long count)
- {
- fRep->Read(destination, count);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::ReadPeek
- //
- // Returns a pointer to a buffer full of data. This data is for reading only and may be
- // used as little or as much as necessary. availableReadBytes has no meaning on input
- // but on output returns the number of bytes that were just returned in the buffer.
- // The user is not responsible for creating the returned buffer and should not try and
- // destroy the buffer.
- // This method does not advance the file pointer. It may also return less data than the
- // buffer size, if the user has already accepted some of the data by calling
- // ReadPeekAdvance.
- //----------------------------------------------------------------------------------------
- const void* FW_CFileSink::ReadPeek(long& availableReadBytes)
- {
- return fRep->ReadPeek(availableReadBytes);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::ReadPeekAdvance
- //
- // This method should be called after ReadPeek to accept bytesRead bytes from the read
- // buffer. This will cause the file position to be advanced by bytesRead from the
- // current position.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::ReadPeekAdvance(long bytesRead)
- {
- fRep->ReadPeekAdvance(bytesRead);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::GetWritableBytes
- //
- // Doesn't make much sense for Files since the file size is effectively unlimited.
- //----------------------------------------------------------------------------------------
- long FW_CFileSink::GetWritableBytes() const
- {
- return LONG_MAX;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::Write
- //
- // Write 'count' bytes to the file from the 'source' buffer. The bytes will be written
- // starting at the current file position. The user is responsible for providing the
- // source buffer.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::Write(const void* source,
- long count)
- {
- fRep->Write(source, count);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::WritePeek
- //
- // Returns a pointer to an empty buffer. The user may write data into this buffer as if
- // she were writing the data directly into the file. The data will not get written to
- // the file though until WritePeekAdvance is called. availableReadBytes has no meaning
- // on input but on output returns the space available in the buffer for writing to.
- // The user is not responsible for creating the returned buffer and should not try and
- // destroy the buffer.
- // This method does not advance the file pointer. It may also return a smaller buffer than the
- // original buffer size, if the user has already flushed some of the data by calling
- // WritePeekAdvance.
- //----------------------------------------------------------------------------------------
- void* FW_CFileSink::WritePeek(long& availableWriteBytes)
- {
- return fRep->WritePeek(availableWriteBytes);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::WritePeekAdvance
- //
- // This method should be called after WritePeek to write bytesWritten bytes to the file
- // from the WritePeek buffer. This will cause the file position to be advanced by
- // bytesWritten bytes from current position.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::WritePeekAdvance(long bytesWritten)
- {
- fRep->WritePeekAdvance(bytesWritten);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::GetLength
- //
- // Returns the length of the file in bytes.
- //----------------------------------------------------------------------------------------
- long FW_CFileSink::GetLength() const
- {
- return fRep->GetLength();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::SetLength
- //
- // Returns the length of the file in bytes.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::SetLength(long length)
- {
- fRep->SetLength(length);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::GetPosition
- //
- // Returns the current file position as a byte offset from the beginning of the file.
- //----------------------------------------------------------------------------------------
- long FW_CFileSink::GetPosition() const
- {
- return fRep->GetPosition();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CFileSink::SetPosition
- //
- // Sets the current file position. length is specified as a byte offset from the
- // beginning of the file. Data will then be read from or written to the new file
- // position.
- //----------------------------------------------------------------------------------------
- void FW_CFileSink::SetPosition(long length)
- {
- fRep->SetPosition(FW_CFileSystem::kFromStart, length);
- }
-